2 extends DialogicPortrait
4 enum Faces {BASED_ON_PORTRAIT_NAME, NEUTRAL, HAPPY, SAD, JOY, SHOCK, ANGRY}
6 @export var emotion: Faces = Faces.BASED_ON_PORTRAIT_NAME
7 @export var portrait_width: int
8 @export var portrait_height: int
9 @export var alien := true
11 var does_custom_portrait_change := true
13 func _ready() -> void:
17 # Function to accept and use the extra data, if the custom portrait wants to accept it
18 func _set_extra_data(data: String) -> void:
21 elif data == "no_alien":
25 # This function can be overridden. Defaults to true, if not overridden!
26 func _should_do_portrait_update(_character: DialogicCharacter, _portrait:String) -> bool:
30 # If the custom portrait accepts a change, then accept it here
31 func _update_portrait(_passed_character: DialogicCharacter, passed_portrait: String) -> void:
32 for face in $Faces.get_children():
35 if emotion == Faces.BASED_ON_PORTRAIT_NAME:
36 if 'happy' in passed_portrait.to_lower(): $Faces/Smile.show()
37 elif 'sad' in passed_portrait.to_lower(): $Faces/Frown.show()
38 elif 'joy' in passed_portrait.to_lower(): $Faces/Joy.show()
39 elif 'shock' in passed_portrait.to_lower(): $Faces/Shock.show()
40 elif 'angry' in passed_portrait.to_lower(): $Faces/Anger.show()
41 else: $Faces/Neutral.show()
44 if emotion == Faces.HAPPY: $Faces/Smile.show()
45 elif emotion == Faces.SAD: $Faces/Frown.show()
46 elif emotion == Faces.JOY: $Faces/Joy.show()
47 elif emotion == Faces.SHOCK: $Faces/Shock.show()
48 elif emotion == Faces.ANGRY: $Faces/Anger.show()
49 else: $Faces/Neutral.show()
51 $Alien.visible = alien
54 func _set_mirror(is_mirrored: bool) -> void:
62 ## If implemented, this is used by the editor for the "full view" mode
63 func _get_covered_rect() -> Rect2:
64 # This will focus on the face.
65 # return Rect2($Faces/Anger.position+$Faces.position, $Faces/Anger.get_rect().size*$Faces/Anger.scale*$Faces.scale)
66 var size: Vector2 = $Body.get_rect().size
67 var scaled_size: Vector2 = size * $Body.scale
68 var position: Vector2 = $Body.position
70 return Rect2(position, scaled_size)